home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyForeBackGround.p < prev    next >
Text File  |  1996-05-29  |  2KB  |  86 lines

  1. unit MyForeBackGround;
  2.  
  3. interface
  4.  
  5.     const
  6.         def_stack = longint(24) * 1024;
  7.         def_masters = 10;
  8.  
  9.     var
  10.         foreground_app: boolean;
  11.  
  12.     procedure InitInForeOrBackground (back_stack, fore_stack: longint; back_masters, fore_masters: integer);
  13.  
  14. implementation
  15.  
  16.     uses
  17.         Types, Resources, Fonts, Windows, QuickDraw, Menus, TextEdit, Dialogs, Memory, LowMem, 
  18.         MyTypes, MySizeResource;
  19.         
  20. {$IFC not GENERATINGPOWERPC}
  21.     function StackPtr: longint;
  22.     inline
  23.         $2E8F;
  24. {$ENDC}
  25.  
  26.     procedure InitInForeOrBackground (back_stack, fore_stack: longint; back_masters, fore_masters: integer);
  27.         const
  28.             CurApNameA = $910;
  29.         var
  30.             size: sizeRsrc;
  31.             i: integer;
  32.             stack, masters: longint;
  33. {$IFC not undefined THINK_Pascal}
  34.             zero: Handle;
  35. {$ENDC}
  36.             applicationZone: THz;
  37.     begin
  38. {$IFC undefined THINK_Pascal}
  39.         InitGraf(@qd.thePort);
  40. {$ELSEC}
  41.         InitGraf(@thePort);
  42. {$ENDC}
  43.  
  44.         GetSizeResource(size);
  45.         foreground_app := not size.only_background;
  46.  
  47. { Check if we are running in the environment }
  48. {$IFC not undefined THINK_Pascal}
  49.         zero := GetResource('ZERO', 0);
  50.         if (zero <> nil) & (HomeResFile(zero) <> CurResFile) then begin
  51.             foreground_app := true;
  52.         end;
  53. {$ENDC}
  54.  
  55.         if foreground_app then begin
  56.             InitFonts;
  57.             InitWindows;
  58.             InitMenus;
  59.             TEInit;
  60.             InitDialogs(nil);
  61.             stack := fore_stack;
  62.             masters := fore_masters;
  63.         end else begin
  64.             stack := back_stack;
  65.             masters := back_masters;
  66.         end;
  67.         if stack = 0 then begin
  68.             stack := def_stack;
  69.         end;
  70.         if masters = 0 then begin
  71.             masters := def_masters;
  72.         end;
  73. {$IFC not GENERATINGPOWERPC}
  74.         SetApplLimit(Ptr(StackPtr - stack));
  75. {$ENDC}
  76.         MaxApplZone;
  77.         for i := 1 to masters do begin
  78.             MoreMasters;
  79.         end;
  80.         applicationZone := GetZone;
  81.         if applicationZone^.bkLim <> LMGetHeapEnd then begin
  82.             LMSetHeapEnd(applicationZone^.bkLim);
  83.         end;
  84.     end;
  85.  
  86. end.